<?php
  class Plugins_Comment extends model {
  
  
  
  function getformadd($productid="")
  {
  
  
  
  
  $echo=1;


$code  = '<div class="wrpCommentArea wrpPlshArea">'."\n";
$code .= '<div class="wrpTtlPlshAddInfoLd">'."\n";
$code .= '<h2 class="ttlPlshAddInfoLd clTxt2 fs03">Comment</h2>'."\n";
$code .= '<p class="rcmPlshAddInfoLd clTxt3 fs01">Who can see this?</p>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpPlsh">'."\n";
$code .= '<input type="radio" checked="" id="everyOne" name="commentstatus[]" value="1">'."\n";
$code .= '<label class="fs03 clTxt3" for="everyOne">Everyone</label>'."\n";
$code .= '<input type="radio" id="onlyMe" name="commentstatus[]" value="2">'."\n";
$code .= '<label class="fs03 clTxt3" for="onlyMe">Only Me</label>'."\n";
$code .= '</div>'."\n";
$code .= '</div>';


$code .= '<div class="wrpPlshArea">'."\n";
$code .= '<div class="wrpTtlPlshAddInfoLd">'."\n";
$code .= '<h2 class="ttlPlshAddInfoLd clTxt2 fs03">Allow to Comment</h2>'."\n";
$code .= '<p class="rcmPlshAddInfoLd clTxt3 fs01">Readers can comment?</p>'."\n";
$code .= '</div>'."\n";
$code .= '<div class="wrpPlsh">'."\n";
$code .= '<input type="radio" checked="" id="al" name="commentstatus2[]" value="1" name="cmAl">'."\n";
$code .= '<label class="fs03 clTxt3" for="al">Allow</label>'."\n";
$code .= '<input type="radio" id="nal" name="commentstatus2[]" value="2" name="cmAl">'."\n";
$code .= '<label class="fs03 clTxt3" for="nal">Not Allow</label>'."\n";
$code .= '</div>'."\n";
$code .= '</div>';
  
  
  
  $arraydata['form']=addslashes(str_replace(array("\r", "", "\r"), '', $code));
 // $arraydata['js'][]=pluginjsinfo.'/image.js';
  //$arraydata['js'][]=baseinfo.'/js/jquery.Jcrop.min.js';
 // $arraydata['js'][]=baseinfo.'/js/jquery.iuploader-1.0.js';
  
  
      
  
  
  
  return $arraydata;
  
  
  
  
  
  
  
  }
  
  function getformlanding($arraydata)
  {
  $code="";

if(count($arraydata['comment']))
{
foreach($arraydata['comment'] as  $valuedata)
{

$code .= '<div class="wrpInCmtLd clBd2 bdBtm" id="commentvalue-'.$valuedata['comvid'].'">'."\n";
$code .= '<img class="genImgUser imgUserCmtLd" src="'.$valuedata['userssimg']['newpath'].'" width="38" height="38" alt="img">'."\n";
$code .= '<div class="cmtLd">'."\n";

if($this->userdata['roleid']=='3')
{
$text='Hide';

if($valuedata['status']=='2')
{
$text='Show';
}
$code .='<div class="wrpHideCmt" onclick="setdatashowcomment('.$valuedata['comvid'].')">
                            <span class="hideCmt fs01 clTxtW clBgBt1">'.$text.' Comment</span>
                        </div>';
}

$code .= '<span class="boldGen userCmtLd cutTxt clTxt2">'.$valuedata['displayname'].'</span>'."\n";

$code .= '<span class="fs01">'.$valuedata['newdate'].'</span><br>'."\n";

$code .= '<span>'.$valuedata['msg'].'</span>'."\n";
$code .='<p onclick="toggledatareply('.$valuedata['comvid'].')" class="replyCmtBtn fs01 clTxt3">reply</p>';
$code .= '</div>'."\n";
$code .= '</div>';



$code .= '<div class="replyCmt clBg4 clBd2 bdBtm" id="recommentvalue-'.$valuedata['comvid'].'">'."\n";
$code .= '<div class="wrpInCmtLd clBd2 bdBtm replyCmtInput" >'."\n";
$code .= '<img width="38" height="38" alt="img" src="'.$this->userdata['simguser'].'" class="genImgUser imgUserCmtLd">'."\n";

$code .= '<div class="cmtLd clearfix">'."\n";
$code .= '<textarea placeholder="Add a Comment" class="fs03 clTxt2 clBg4 clBd2 bdFull mgBtm10"></textarea>'."\n";
$code .= '<input type="button" onclick="savecommentpost('.$arraydata['productid'].','.$valuedata['comvid'].')" value="Reply" class="btnGen btnCmt clTxtW cutTxt clBgSp2 fs04">'."\n";
$code .= '</div>'."\n";

$code .= '</div>'."\n";



if(count($valuedata['reply']))
{
foreach($valuedata['reply'] as  $valuedata2)
{
$code .= '<div class="wrpInCmtLd clBd2 bdBtm replydatasetvalue" id="commentvalue-'.$valuedata2['comvid'].'">'."\n";
$code .= '<img width="38" height="38" alt="img" src="'.$valuedata2['userssimg']['newpath'].'" class="genImgUser imgUserCmtLd">'."\n";
$code .= '<div class="cmtLd">'."\n";

if($this->userdata['roleid']=='3')
{
$text='Hide';

if($valuedata2['status']=='2')
{
$text='Show';
}
$code .='<div class="wrpHideCmt" onclick="setdatashowcomment('.$valuedata2['comvid'].')">
                            <span class="hideCmt fs01 clTxtW clBgBt1">'.$text.' Comment</span>
                        </div>';
}


$code .= '<span class="boldGen userCmtLd clTxt2">'.$valuedata2['displayname'].'</span>'."\n";
$code .= '<span class="fs01">'.$valuedata2['newdate'].'</span><br>'."\n";
$code .= '<span>'.$valuedata2['msg'].'</span>'."\n";
$code .= '</div>'."\n";
$code .= '</div>';
}

if(count($valuedata['reply'])>19)
{
$code.='<button class="btnSeeMore clTxt3 fs02" onclick="loadmorecomment('.$arraydata['productid'].','.$valuedata['comvid'].')">See More</button>';
}


}


$code .= '</div>';


}

}
if(count($arraydata['comment'])>19)
{
$code.='<button class="btnSeeMore clTxt3 fs02" onclick="loadmorecomment('.$arraydata['productid'].')">See More</button>';
}

 $data['str']=$code;
 $data['target']='commenttarget';
 $strset='';
 if($arraydata['nopost'])
 {
 $strset='hidepostdata();';
 
 }
 
 
 $data['script']="initcommenddata();".$strset;
 if($arraydata['nocomment'])
 {
 $data['script'].= $data['script']."nocommendata();";
 }
  
  return $data; 
  
  
  }
  
 function getplugincomment($page,$productid,$recomvid='0')
 {
 
 $page=(($page - 1) * 20);
 
$sqlset=' and tb_plugins_comment_value.status=1';
 if($this->userdata['roleid']=='3')
{
$sqlset='';

}
 
 $sql="select tb_plugins_comment_value.msg,tb_plugins_comment_value.comvid,tb_plugins_comment_value.createdate,DATE_FORMAT(tb_plugins_comment_value.createdate,'%d/%m/%Y %h:%i %p') newdate,IF (tb_user.displayname = '', tb_user.username,tb_user.displayname) as displayname,tb_user.username,tb_user.imgmid as userimgmid,tb_user.simgmid as usersimgmid,tb_plugins_comment_value.status from tb_plugins_comment_value inner join tb_user ON tb_user.userid=tb_plugins_comment_value.createby   where tb_plugins_comment_value.productid=".$productid." and tb_plugins_comment_value.recomvid=".$recomvid." ".$sqlset." order by tb_plugins_comment_value.createdate desc  limit ".$page.",20";

  $arrayplugin2=$this->db->db_set_recordset($sql);
  if(count($arrayplugin2))
  {
  $k=0;
  foreach($arrayplugin2 as $valueplugins2)
  {

     
     $arrayplugin2[$k]['usersimg']= $this->getimagebyimgmid($valueplugins2['userimgmid']);
     $arrayplugin2[$k]['userssimg']= $this->getimagebyimgmid($valueplugins2['usersimgmid']);
     
     if($recomvid=='0')
     {
     $arrayplugin2[$k]['reply']=$this->getplugincomment(1,$productid,$valueplugins2['comvid']);
     
     }else
     {
     
     $arrayplugin2[$k]['reply']=array();
     
     }
     
  
  
  $k++;
  
  }
       
  }
  
  

  
  return $arrayplugin2;
 
 }
  
  function getplugin($plugreid)
  {
  
  
  $sql="select * from tb_plugins_comment where plugreid=".$plugreid;
  $arrayplugin=$this->db->db_set_1recordrow($sql);
  
  $arrayplugin['comment']=array();
  $arrayplugin['nocomment']=1;
  if($arrayplugin['status']=="1")
  {
//  $sql="select * from tb_plugins_comment_value where productid=".$arrayplugin['productid']." limit 0,20";
//  $arrayplugin2=$this->db->db_set_recordset($sql);
  $arrayplugin['comment']=$this->getplugincomment(1,$arrayplugin['productid']);
  
  $arrayplugin['nocomment']=0;
  }else if($this->userdata['oauth'])
  {
  
   $arrayuser=$this->getuserbyoauth($this->userdata['oauth']);
   
   $sql="select productid from tb_product where productid=".$arrayplugin['productid'].' and createby='.$arrayuser['userid'];
   $arrayplugin3=$this->db->db_set_1recordrow($sql);
   if($arrayplugin3['productid'])
   {
   $arrayplugin['nocomment']=0;
   $arrayplugin['comment']=$this->getplugincomment(1,$arrayplugin['productid']);
   
   }
  
  
  }
  
  $arrayplugin['nopost']=1;
  if($arrayplugin['statuscomment']=="1")
  {
  $arrayplugin['nopost']=0;
  
  }
  
  

  
  
    return $arrayplugin;
  
  
  }
    
  function saveplugin($arraydata,$productid,$plugreid)
  {
  
  
  $arraydata['productid']=$productid;
  $arraydata['plugreid']=$plugreid;
  
  

  
  
  
  $this->db->db_set($arraydata,'tb_plugins_comment');
  
  }
  function showhidecomment()
  {
       $arraydata['data']=array();    
       if($this->userdata['oauth'])
   {
     $userdata=$this->getuserbyoauth($this->userdata['oauth']);
   
   
    if($userdata['roleid']=='3')
    {
    $sql='select comvid,status from tb_plugins_comment_value where comvid='.$_POST['comvid'];
 
    $arraycheckcom=$this->db->db_set_1recordrow($sql);
    if($arraycheckcom['comvid'])
    {
    
     $status=2; 
    if($arraycheckcom['status']=='2')
    {
    
    $status=1;
    }
    
    $arrayset['status']=$status;
    $this->db->db_set($arrayset,'tb_plugins_comment_value',' comvid='.$_POST['comvid']);
    
    }
    }
    
   }else
   {
   $arraydata['error'][]=5;
   
   }
   
   return         $arraydata['data'];
  
  
  }
  function savecomment()
  {
         $arraydata['data']=array();    
       if($this->userdata['oauth'])
   {
     $userdata=$this->getuserbyoauth($this->userdata['oauth']);
   
   
   
    $sql='select comvid from tb_plugins_comment_value where productid='.$_POST['productid'].' and createby='.$userdata['userid'];
 
    $arraycheckcom=$this->db->db_set_1recordrow($sql);
    if(!$arraycheckcom['comvid'])
    {
    //$this->savescoredata($userdata['userid'],4);
    $this->savegamenictaionbygxcid($userdata['userid'],4);
    }
   
   
    $arraysetdata['productid']=$_POST['productid'];;
    $arraysetdata['msg']=$_POST['msg'];
    
    if($_POST['comvid'])
    {
    $arraysetdata['recomvid']=$_POST['comvid'];
    
    }
    
    $arraysetdata['updateby']=$userdata['userid'];
    $arraysetdata['updatedate']=date("Y-m-d H:i:s");
    $arraysetdata['createby']=$userdata['userid'];
    $arraysetdata['createdate']=date("Y-m-d H:i:s");
    $this->db->db_set($arraysetdata,'tb_plugins_comment_value');
    

    
    
    
      $comid=$this->db->db_get_last_number();
           
      $sql="select tb_product.productid,tb_product.title,tb_product.createby from tb_product   where tb_product.productid=".$_POST['productid'];
      $dataproduct=$this->db->db_set_1recordrow($sql);  
      $userid=$dataproduct['createby']; 
      $arraydataset['userid']=$userid;
      $arraydataset['createby']=$userdata['userid'];
      $arraydataset['conid']=40;
      $arraydataset['comid']=$comid;
      $notiid[$userid]=$this->savenotificationlist($arraydataset);
            
      $msgto=$userdata['displayname'].' '.$this->getconditionmsgbyid(40).' '.$msg;
      $arraydatanow[]=$userid;
      //$this->sendtonotification($arraydatanow,$msgto,$notiid);
    
    
    
    
   
   }else
   {
   $arraydata['error'][]=5;
   
   }
  
              return         $arraydata['data'];
  
  }
  
  
  
  
  }
?>
